package edu.fudan.jwxt.utils;

import edu.fudan.jwxt.entity.Course;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

public class CSVReader {

    public static List<Course> ReadCourseCSV(String Path){
        List<Course> ListOfCourses= new ArrayList<>();
        try {
            BufferedReader reader = new BufferedReader(new FileReader(Path));
            reader.readLine();//第一行信息，为标题信息，不用，如果需要，注释掉
            String line = null;
            while ((line = reader.readLine()) != null) {
                //System.out.println("Now line is "+ line);
                String item[] = line.split(",");//CSV格式文件为逗号分隔符文件，这里根据逗号切分
                //System.out.println(item.length);
                Course newcourse = new Course(item);
                ListOfCourses.add(newcourse);
                //System.out.println(newcourse);

            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
        return ListOfCourses;
    }

    public static void main(String[] args) {
        List<Course> ListOfCourses= ReadCourseCSV("C:\\local_jwxt\\course.csv");
        for (Course i:
                ListOfCourses) {
            System.out.println(i);
        }
    }

}

